package com.china08.yxyapi.entity.mg.office;

import java.util.List;

import javax.persistence.Id;

import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

import com.china08.yxyapi.entity.mg.MongoBaseEntityNoId;

/**
 * 学校办公通知，教育局办公通知
 * 
 * @author
 *
 */
@Document(collection = "yxy.oa.notice.inner")
public class YxyNoticeInner extends MongoBaseEntityNoId {

    /**
     * 
     */
    private static final long serialVersionUID = 4231188624924981059L;

    @Id
    private String id;

    /** The user id. 发件人id */
    @Indexed
    @Field(value = "user_id")
    private String userId;

    /**
     * 用户头像
     */
    @Field(value = "avatar")
    private String avatar;

    /** The user . 发件人名称 */
    @Field(value = "user_nick")
    private String userNick;

    /** The title. 标题 */
    @Field(value = "title")
    private String title;

    /** The content. 内容 */
    @Field(value = "content")
    private String content;

    @Field(value = "school_id")
    private String schoolId;

    @Field(value = "school_nick")
    private String schoolNick;

    /**
     * ，
     */
    @Field(value = "receiver")
    private List<YxyNotifictionTea> receiver;

    /**
     * 图片附件,可以放置多张图片
     */
    @Field(value = "image")
    private List<String> image;

    /** The adjunct. 附件的文件路径,附件原始文件名称。 */
    @Field(value = "attachment_name")
    private String attachmentName;

    @Field(value = "attachment_path")
    private String attachmentPath;

    /** The status.状态 -1：发件人已删除 0：发件人已发出 */
    @Field(value = "delete_status")
    private int deleteStatus = 0;

    // 判断当前用户是否在收件箱中，在收集箱中获取当前用户的详细信息
    public YxyNotifictionTea getCurrentReceiver(String userId) {
        for (YxyNotifictionTea yxyNotifictionTea : receiver) {
            if (yxyNotifictionTea.getUserId().equals(userId)) { //
                return yxyNotifictionTea;
            }
        }
        return null;
    }

    // 内部通信 获取所有的接受用户名称
    public String getAllReceiverUserNick(String splitStr) {
        StringBuilder receverUserNickStr = new StringBuilder();
        for (YxyNotifictionTea yxyNotifictionTea : receiver) {
            if (!"".equals(yxyNotifictionTea.getUserNick()) && yxyNotifictionTea.getUserNick() != null) {
                receverUserNickStr.append(yxyNotifictionTea.getUserNick()).append(splitStr);
            }
        }
        if (receverUserNickStr.length() > 0) {//
            return receverUserNickStr.substring(0, receverUserNickStr.length() - 1).toString();
        }
        return receverUserNickStr.toString();
    }

    // 获取已收到人数 1 或 未收到人数 0
    public long getReadManCount(int isRead) {
        // long count = receiver.stream().filter(x -> {
        // return x.getIsRead() == isRead;
        // }).collect(Collectors.counting());
        long count = 0l;
        for (YxyNotifictionTea yxyNotifictionTea : receiver) {
            if (yxyNotifictionTea.getIsRead() == isRead) {
                count++;
            }
        }
        return count;
    }

    // 获取已收到人员字符串拼接列表 1 或 未收到人员字符串拼接列表 0
    public String getReadManUserNicknameStr(int isRead, String splitStr) {
        StringBuffer readManUserNicknameStr = new StringBuffer();
        readManUserNicknameStr.append("");
        for (YxyNotifictionTea yxyNotifictionTea : receiver) {
            if (yxyNotifictionTea.getIsRead() == isRead) {
                readManUserNicknameStr.append(yxyNotifictionTea.getUserNick()).append(splitStr);
            }
        }
        if (readManUserNicknameStr.length() < 2) { return readManUserNicknameStr.toString(); }
        return readManUserNicknameStr.toString().substring(0, readManUserNicknameStr.length() - 2);
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getUserNick() {
        return userNick;
    }

    public void setUserNick(String userNick) {
        this.userNick = userNick;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getSchoolId() {
        return schoolId;
    }

    public void setSchoolId(String schoolId) {
        this.schoolId = schoolId;
    }

    public List<YxyNotifictionTea> getReceiver() {
        return receiver;
    }

    public void setReceiver(List<YxyNotifictionTea> receiver) {
        this.receiver = receiver;
    }

    public List<String> getImage() {
        return image;
    }

    public void setImage(List<String> image) {
        this.image = image;
    }

    public String getAttachmentName() {
        return attachmentName;
    }

    public void setAttachmentName(String attachmentName) {
        this.attachmentName = attachmentName;
    }

    public String getAttachmentPath() {
        return attachmentPath;
    }

    public void setAttachmentPath(String attachmentPath) {
        this.attachmentPath = attachmentPath;
    }

    public int getDeleteStatus() {
        return deleteStatus;
    }

    public void setDeleteStatus(int deleteStatus) {
        this.deleteStatus = deleteStatus;
    }

    public static class YxyNotifictionTea {

        // 用户id
        private String userId;
        // 用户昵称
        private String userNick;
        // 0 未读 1 已读
        private int isRead = 0;
        // 0 存在 -1 已删除
        private int isDelete = 0;

        public String getUserId() {
            return userId;
        }

        public void setUserId(String userId) {
            this.userId = userId;
        }

        public String getUserNick() {
            return userNick;
        }

        public void setUserNick(String userNick) {
            this.userNick = userNick;
        }

        public int getIsRead() {
            return isRead;
        }

        public void setIsRead(int isRead) {
            this.isRead = isRead;
        }

        public int getIsDelete() {
            return isDelete;
        }

        public void setIsDelete(int isDelete) {
            this.isDelete = isDelete;
        }

    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getSchoolNick() {
        return schoolNick;
    }

    public void setSchoolNick(String schoolNick) {
        this.schoolNick = schoolNick;
    }

}
